
use processed/RPImicro,clear
forvalues x = 1/17	 {
gen b`x' = s_RPI_`x'
drop if b`x' ==.
}
drop if I ==.
drop if I < 0

** Young

gen flag_agehd = 0 
replace flag_agehd = 1 if agehd > 50	
tabstat I  if datayear ==2017, by(flag_agehd) stats(n mean median min max)


forvalues p = 0/1  {

preserve 
*keep if penflag == 1`p'
keep if flag_agehd == `p'


gen logI = log(I)
gen logI2 = log(I)*log(I)
gen logI3 = log(I)*log(I)*log(I)
keep if I > 0
qui forvalues x = 1/17	 {
keep if b`x' <1 
keep if b`x' > -0.00001 
}

qui forvalues x = 1/17	 {
	reg b`x' logI  logI2  if datayear ==1974 , vce(robust)
	predict tmp if e(sample), xb 
	gen b`x'_hat = tmp
	drop tmp
}



qui forvalues t = 1975/2017 {

qui forvalues x = 1/17	 {
	reg b`x' logI  logI2  if datayear ==`t' , vce(robust)
	predict tmp if e(sample), xb 
	replace b`x'_hat = tmp if datayear == `t'
	drop tmp
}


  
}

keep datayear I b1_hat b2_hat b3_hat b4_hat b5_hat b6_hat b7_hat b8_hat b9_hat b10_hat b11_hat b12_hat b13_hat b14_hat b15_hat b16_hat b17_hat weight caseno
duplicates drop caseno datayear,force
drop caseno

outsheet using DataforMatlab\UK_Budget_`p'.csv, comma replace nonames

restore 

}
